package com.seadragon.app.ksr.model;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.Type;
import org.joda.time.LocalDate;
import org.joda.time.LocalTime;

@Entity
@Table(name = "EVENT_SCHEDULE", schema = "STAGING")
public class EventSchedule {
	@Id
	@Column(name = "ID")
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "EVENTSCHEDULEIDSEQ")
	@SequenceGenerator(name = "EVENTSCHEDULEIDSEQ", sequenceName = "STAGING.EVENT_SCHEDULE_ID_SEQ", schema = "STAGING")
	private long id;

	@ManyToOne
	@JoinColumn(name="EVENT_ID")
	private Event event;
	
	@Column(name="OPENING_TIME", nullable = true)
	@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalTime")
	private LocalTime openingTime;

	@Column(name="CLOSING_TIME", nullable = true)
	@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalTime")
	private LocalTime closingTime;

	@Column(name="START_DATE", nullable = true)
	@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
	private LocalDate startDate;

	@Column(name="END_DATE", nullable = true)
	@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
	private LocalDate endDate;

	/**
	 * It could be business day, weekly, biweekly, twice a week, monthly.
	 */
	@Column(name="EVENT_SCHEDULE_TYPE")
	private String scheduleType;

	@ManyToMany(fetch=FetchType.EAGER, cascade=CascadeType.PERSIST)
	@Fetch(value = FetchMode.SUBSELECT)
	@JoinTable(schema="STAGING", name="EVENT_SCHEDULE_ADDRESS", 
	      joinColumns=@JoinColumn(name="EVENT_SCHEDULE_ID"),
	      inverseJoinColumns=@JoinColumn(name="ADDRESS_ID"))  
	private List<Address> eventAddresses;

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public Event getEvent() {
		return event;
	}

	public void setEvent(Event event) {
		this.event = event;
	}

	public LocalTime getOpeningTime() {
		return openingTime;
	}

	public void setOpeningTime(LocalTime openingTime) {
		this.openingTime = openingTime;
	}

	public LocalTime getClosingTime() {
		return closingTime;
	}

	public void setClosingTime(LocalTime closingTime) {
		this.closingTime = closingTime;
	}

	public LocalDate getStartDate() {
		return startDate;
	}

	public void setStartDate(LocalDate startDate) {
		this.startDate = startDate;
	}

	public LocalDate getEndDate() {
		return endDate;
	}

	public void setEndDate(LocalDate endDate) {
		this.endDate = endDate;
	}

	public String getScheduleType() {
		return scheduleType;
	}

	public void setScheduleType(String scheduleType) {
		this.scheduleType = scheduleType;
	}
	
	public List<Address> getEventAddresses() {
		return eventAddresses;
	}

	public void setEventAddresses(List<Address> eventAddresses) {
		this.eventAddresses = eventAddresses;
	}
}
